<template>
  <el-dialog width="49%" v-model="visible" title="图标选择" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-tabs v-model="activeTab">
      <el-tab-pane v-for="item in icons" :key="item.id" :label="item.label" :name="item.id">
        <div :class="['icon-container', { grow: item.id == 'ym' || item.id == 'ym-custom' }]">
          <div v-for="(icon, index) in item.data" :key="index" :class="['icon-item', { 'icon-active': icon.name == iconName }]" @click="iconName = icon.name">
            <span :class="icon.name" />
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="confirm">保存</el-button>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { uview, element, vant, ym, ymCustom } from './source'

const visible = ref(false)
const iconName = ref('')
const activeTab = ref('uview')
const icons = ref([
  {
    id: 'uview',
    label: 'uview图标',
    data: uview
  },
  {
    id: 'elementui',
    label: 'element图标',
    data: element
  },
  {
    id: 'vant',
    label: 'vant图标',
    data: vant
  },
  {
    id: 'ym',
    label: 'ym图标',
    data: ym
  },
  {
    id: 'ym-custom',
    label: '更多图标',
    data: ymCustom
  }
])

const emits = defineEmits<{
  (e: 'confirm', name: string): void
}>()

function init(name: string) {
  visible.value = true
  iconName.value = name
}

function confirm() {
  emits('confirm', iconName.value)
  visible.value = false
}

defineExpose({ init })
</script>
<style scoped>
.icon-container {
  width: 100%;
  height: 550px;
  overflow-y: hidden;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
}

.icon-container .icon-item {
  width: 50px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid #eaeefb;
  border-radius: 4px;
  font-size: 20px;
  cursor: pointer;
  color: #606266;
  margin-left: 5px;
  margin-top: 5px;
}

.icon-container .icon-item:hover {
  border: 1px dashed #00a2ff;
  color: #00a2ff;
}

.icon-active {
  border: 1px solid #00a2ff!important;
  color: #00a2ff!important;
}

.grow span {
  transform: scale(1.2)
}
</style>
